// pages/evaluate/evaluate.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        img_path: "../../images/xj.jpg"
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        var sub_order_id = options.sub_order_id;
        var goods_name = options.goods_name;
        that.setData({
            sub_order_id: sub_order_id,
            goods_name: goods_name
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    textarea_event: function (e) {
        var that = this;
        var evaluate_content = e.detail.value;
        that.setData({
            content: evaluate_content
        })
    },
    submit: function () {
        var that = this;
        var product_order_id = that.data.sub_order_id;
        var content = that.data.content;
        var params = {};
        params['product_order_id'] = product_order_id;
        if (content) {
            params['content'] = content;
        } else {

        }
        wx.request({
            url: app.config() + "order/discussSubmit",
            data: params,
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                if (res.data.status == 0) {
                    wx.showToast({
                        title: '感谢您的评价',
                        icon: "success"
                    })
                }
            }
        })
    },//上传图片
    chooseImageTap: function () {
        var that = this;
        wx.showActionSheet({
            itemList: ['从相册中选择', '拍照'],
            itemColor: "#5673b8",
            success: function (res) {
                if (!res.cancel) {
                    if (res.tapIndex == 0) {
                        that.chooseWxImage('album')
                    } else if (res.tapIndex == 1) {
                        that.chooseWxImage('camera')
                    }
                }
            }
        })
    },//主要是用来选择图片以及接收图片路径回调的监听
    chooseWxImage: function (type) {
        var that = this;
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['original'],
            sourceType: [type],
            success: function (res) {
                that.setData({
                    img_path: res.tempFiles[0].path,
                })
                var params = {};
                params['type'] = 2;
                params['product_order_id'] = that.data.sub_order_id;
                params['index'] = 1;
                wx.uploadFile({
                    url: app.config() + "order/uploadDiscussAftersaleImg", //仅为示例，非真实的接口地址
                    filePath: res.tempFilePaths[0],
                    name: 'upload',
                    formData: params,
                    success: function (res) {
                        var data = res.data
                        //do something
                    }
                })

            }
        })
    },
    upload_img: function () {
        var params = {};
        params['type'] = 2;
        params['product_order_id'] = that.data.sub_order_id;
        params['index'] = 1;
        var form_data = new FormData();
        form_data.append("upload", res.tempFiles[0].path);
        params['upload'] = res.tempFiles[0].path;
        wx.request({
            url: app.config() + "order/uploadDiscussAftersaleImg",
            data: params,
            header: {
                'content-type': 'application/json'
            }
        })
    }
})